package com.aoxin.service.impl.opm;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.aoxin.mapper.opm.SlfRoleMenuMapper;
import com.aoxin.model.opm.SlfRoleMenu;
import com.aoxin.service.inter.opm.RoleMenuService;
import com.aoxin.util.ErrorUtil;

@Service("roleMenService")
public class RoleMenuServiceImpl implements RoleMenuService {
	
	@Autowired
	private SlfRoleMenuMapper slfRoleMenuMapper;

	@Override
	@Transactional
	public void insertSlfRoleMenuList(Integer roleId, List<Integer> menuIds) {
		Assert.notNull(roleId, String.format(ErrorUtil.PARAMETER_NULL, "roleId"));
		Assert.notEmpty(menuIds, String.format(ErrorUtil.PARAMETER_NULL, "menuIds"));
		this.slfRoleMenuMapper.deleteByRole(roleId);
		for (Integer integer : menuIds) {
			SlfRoleMenu roleMenu = new SlfRoleMenu();
			roleMenu.setMenuId(integer);
			roleMenu.setRoleId(roleId);
			this.slfRoleMenuMapper.insertSelective(roleMenu);
		}
	}

	@Override
	@Transactional
	public void deleteSlfRoleMenuByIds(List<Integer> roleMenuIds) {
		Assert.notEmpty(roleMenuIds, String.format(ErrorUtil.PARAMETER_NULL, "roleMenuIds"));
		this.slfRoleMenuMapper.deleteByPrimaryKeys(roleMenuIds);
	}

	@Override
	@Transactional
	public void updateSlfRoleMenu(SlfRoleMenu roleMenu) {
		Assert.notNull(roleMenu, String.format(ErrorUtil.PARAMETER_NULL, "roleMenu"));
		this.slfRoleMenuMapper.updateByPrimaryKeySelective(roleMenu);
	}

	@Override
	public SlfRoleMenu getSlfRoleMenu(Integer roleMenuId) {
		Assert.notNull(roleMenuId, String.format(ErrorUtil.PARAMETER_NULL, "roleMenuId"));
		return this.slfRoleMenuMapper.selectByPrimaryKey(roleMenuId);
	}
}
